package com.smcdd.cdb.dbo.cdb_dbo.ui.activity;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.smcdd.cdb.dbo.cdb_dbo.R;
import com.smcdd.cdb.dbo.cdb_dbo.service.presenter.HardwarePresenter;
import com.smcdd.cdb.dbo.cdb_dbo.service.presenter.NetInPresenter;
import com.smcdd.cdb.dbo.cdb_dbo.service.view.IHardwareAc;
import com.smcdd.cdb.dbo.cdb_dbo.service.view.INetInAc;
import com.smcdd.cdb.dbo.cdb_dbo.ui.base.BaseActivity;
import com.smcdd.cdb.dbo.cdb_dbo.ui.utils.ObtainUdis;
import com.smcdd.cdb.dbo.cdb_dbo.ui.utils.ToastUtil;

/**
 * 作者：Administrator on 2017/6/21 11:12
 * 邮箱：zhanghuaiha@gmail.com
 * 硬件故障
 */

public class HardwareActivity extends BaseActivity<IHardwareAc,HardwarePresenter> implements IHardwareAc{
    private ImageView back;
    private TextView net_id,net_name,net_save,net_number;
    private EditText net_remarks;
    private String alias;
    private String udid;

    @Override
    public void initView() {
        back = (ImageView) findViewById(R.id.net_back);
        net_id = (TextView) findViewById(R.id.net_id);
        net_name = (TextView) findViewById(R.id.net_name);
        net_save = (TextView) findViewById(R.id.net_save);
        net_number = (TextView) findViewById(R.id.net_number);
        net_remarks = (EditText) findViewById(R.id.net_remarks);
    }

    @Override
    public void initData() {
        alias = getIntent().getStringExtra("alias");
        udid = ObtainUdis.getUDID(HardwareActivity.class);
        net_id.setText(alias);
        mPresenter.loadContacts();
    }

    @Override
    public void initListener() {
        back.setOnClickListener(v -> finish());
        net_save.setOnClickListener(v -> {
            String trim = net_remarks.getText().toString().trim();
            if (TextUtils.isEmpty(trim)) {
                ToastUtil.showToast("故障信息不能为空");
                return;
            }
            mPresenter.loadData(alias,udid,trim);
        });
        net_remarks.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
              //  Log.e("aaa",s.length()+"");
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
               // Log.e("bbbbb",s.length()+"");
            }

            @Override
            public void afterTextChanged(Editable s) {
               // Log.e("cccc",s.length()+"");
                net_number.setText(s.length()+"/100");

            }
        });
    }

    @Override
    protected HardwarePresenter createPresenter() {
        return new HardwarePresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_hardware;
    }

    @Override
    public EditText getET() {
        return net_remarks;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.unLoadData();
    }
}
